package hust.ning.xiaonei
{
	import flash.net.*;
	
	import hust.ning.util.URLParser;
	import flash.events.Event;	
	public class XiaoneiClient
	{
		public function XiaoneiClient()
		{
			params = URLParser.getParams();
		}
		private var params:Object;
		public function getMyXiaoneiId()
		{
			return params.xn_sig_user;
		}
		public function getUserInfo(uid:String,handler:Function)
		{
			var args:URLVariables = new URLVariables();
//			args.session_key="2.eb49d5d3841f28aee4fd2d891a5d0d7a.3600.1240916400-913635539";
			args['session_key']=params.xn_sig_session_key;
			args.fields="name,sex,tinyurl,headurl,mainurl";
			args.uids=uid;//wr哦。掉了个s.
			
			args.call_id="1240913749234";
			args.sig="334461d41303f906ab97fe395e502089";

			args.api_key="9efcae555af746f58d14e7e8df5e310d";
			args.method="xiaonei.users.getInfo";
			args.v="1.0";
			doPost("http://api.xiaonei.com/restserver.do",handler,args);
		}
		private function doPost(url:String,handler:Function,args:URLVariables=null):void
		{
			var request:URLRequest = new URLRequest(url);
			request.data=args;
			request.method=URLRequestMethod.POST;
			var loader:URLLoader = new URLLoader();
			
			loader.dataFormat = URLLoaderDataFormat.TEXT;
			loader.addEventListener(Event.COMPLETE, handler);
			try
			{
				loader.load(request);
			}
			catch (error:Error)
			{
				trace("Unable to load URL: " + error);
			}
		}
	}
}